import {Buffer} from "buffer";
import {HdlcAddress} from "./HdlcAddress";


export class HdlcAddressPair {

    cliAddr : Buffer | null = null;
    srvAddr : HdlcAddress | null = null;

    constructor(srvAddr : HdlcAddress, cliAddr : Buffer) {
        this.cliAddr = cliAddr;
        this.srvAddr = srvAddr;
    }

    getCliAddr() : Buffer{
        if(this.cliAddr != null){
            return this.cliAddr;
        }else{
            throw new Error("cliAddr is null");
        }
    }

    getSrvAddr() : HdlcAddress{
        if(this.srvAddr){
            return this.srvAddr;
        }else{
            throw new Error("srvAddr is null");
        }
    }

    switchedPair() : HdlcAddressPair{
        if(this.srvAddr != null && this.cliAddr != null){
            return new HdlcAddressPair(this.srvAddr, this.cliAddr);
        }else{
            throw new Error("srvAddr or cliAddr is null");
        }
    }

    toString() : string{
        if(this.cliAddr != null || this.srvAddr != null){
            return this.cliAddr + ":" + this.srvAddr;
        }else{
            return "cliAddr or srvAddr is null";
        }
    }

}
